package web.demo.factory;

import java.util.ResourceBundle;

import web.demo.dao.impl.FoodTypeDao;
/**
 * 工厂模式
 * 加载资源文件，通过key和字节码文件，获取对象
 * 利于维护和扩展
 * */
public class BeanFactory {
	private static ResourceBundle bundle;
	static{
		bundle=ResourceBundle.getBundle("instance");
	}
	
	public static <T> T getInstance(String key, Class<T> clazz){
		try{
			String className=bundle.getString(key);
			//通过加载类的字节码文件实例化对象
			return (T)Class.forName(className).newInstance();
		}catch(Exception e){
			throw new RuntimeException(e);
		}
	}
	
	public static void main(String[] args) {
		/*FoodTypeDao dao=BeanFactory.getInstance("foodTypeDao",FoodTypeDao.class);
		
		System.out.println(dao);*/
	}
}
